<?php
	require_once('../conn/DBconnect.php');
	session_start();
	
	if(isset($_POST["r_size"]))
	{
		setcookie("r_size",  $_POST["r_size"], time()+3600);
		$_SESSION['r_size'] = $_POST["r_size"];
	}
		
	if(isset($_POST["r_color"]))
	{
		setcookie("r_color",  $_POST["r_color"], time()+3600);
	 	$_SESSION['r_color'] = $_POST["r_color"];
	}
	
	$params[0] = "TEMP_RECORD";
	$params[1] = "0";
 	$params[2] = "0";
 	$params[3] = $_SESSION["r_firstName"];
 	$params[4] = $_SESSION["r_lastName"];
 	$params[5] = $_SESSION["r_middle_ini"];
 	$params[6] = $_SESSION["r_gender"];
 	$params[7] = $_SESSION["r_birthdate"];
 	$params[8] = $_SESSION["r_email"];
 	$params[9] = $_SESSION["r_mobile"];
 	$params[10] = $_SESSION["r_nationality"];
 	$params[11] = $_SESSION["r_country"];
 	$params[12] = $_SESSION["r_address1"];
 	$params[13] = $_SESSION["r_address2"];
 	$params[14] = $_SESSION["r_delivery_add"];
 	$params[15] = $_SESSION["r_contact_name"];
 	$params[16] = $_SESSION["r_contact_phone"];
 	$params[17] = $_SESSION["r_size"];
 	$params[18] = $_SESSION["r_color"];
 	$params[19] = "1";
 	$params[20] = "0";
 	$params[21] = "0";
 	$params[22] = $_SESSION["r_race_code"];
 	$params[23] = "0";
 	$params[24] = $_SESSION["transID"];
 	
 	$insertPROC = "CALL SP_REGISTRATION('" . implode("', '", $params) . "');";
	$result = mysqli_query($mysqlLink, $insertPROC);
	$row = mysqli_fetch_array($result, MYSQLI_ASSOC);
	
	mysqli_free_result($result);
	mysqli_next_result($mysqlLink); 
	if( $row["err_id"] != '-1')
	{
 	
	 	$paramRC = GetSQLValueString($_POST["r_race_code"],"text");
	 	$paramKSCode = GetSQLValueString($_POST["r_size"],"text");
	 	
	 	$raceCatSQL = "call sp_race('RECORD','RACE_CODE',".$paramRC.");";
	
		$result = mysqli_query($mysqlLink, $raceCatSQL);
		$raceData = mysqli_fetch_object($result);
		
		mysqli_free_result($result);
		mysqli_next_result($mysqlLink); 
		
		$kitSizeSQL = "call sp_kit('RECORD','KIT_SIZE', 1, 1,".$paramKSCode.");";
	
		$ksResult = mysqli_query($mysqlLink, $kitSizeSQL);
		$ksData = mysqli_fetch_object($ksResult);
		
		mysqli_free_result($ksResult);
		mysqli_next_result($mysqlLink); 
		//mysqli_close($mysqlLink);
		
		$totalFee = $raceData->rc_reg_fee;
?>

<div id="div-container">
	<div id="div-header">
		<div class="div-header-title">
			<div class="dh-title-left"></div>
			<div class="dh-title-center">Review cart</div>
			<div class="dh-title-right"></div>
		</div>
	</div>
	<div id="div-content">
		<div class="formItem">
			<div class="formTitleLabel" style="width:150px;padding-top:2px;">COLOR MANILA RUN- </div>
			<div class="formLabel"><?php echo $raceData->race_distance ?> Run</div>
		</div>
		<div class="formItem">
			<div class="formLabel" style="width:90px; font-weight: bold">Participant: </div>
			<div class="formLabel"><?php echo $_POST["r_firstName"]." ".$_POST["r_lastName"] ?></div>
		</div>
		<div class="formItem">
			<div class="formLabel" style="width:270px;font-weight: bold">Items</div>
			<div class="formLabelRight" style="width:90px;font-weight: bold;">Price</div>
			<div class="formLabelRight" style="width:90px;font-weight: bold;">Quantity</div>
			<div class="formLabelRight" style="width:90px;font-weight: bold;">Total</div>
		</div>
		<div>
			<div style="width:580px;padding:2px 10px;">
				<hr class="hrDashedThin">
			</div>
		</div>
		<div class="formItem">
			<div class="formLabel" style="width:270px;"><?php echo $raceData->race_distance ?> Run</div>
			<div class="formLabelRight" style="width:90px;">Php <?php echo $raceData->rc_reg_fee ?></div>
			<div class="formLabelRight" style="width:90px;">1</div>
			<div class="formLabelRight" style="width:90px;">Php <?php echo $raceData->rc_reg_fee ?></div>
		</div>
		<div class="formItem">
			<div class="formLabel" style="width:270px;">COLOR MANILA T-shirt size - <?php echo $ksData->ks_desc ?></div>
			<div class="formLabelRight" style="width:90px;">Php 0.00</div>
			<div class="formLabelRight" style="width:90px;">1</div>
			<div class="formLabelRight" style="width:90px;">Php 0.00</div>
		</div>
		
		<?php 
		if(isset($_POST["withAddRunners"]))
		{
			$runrparams[0] = "GET_TOTAL_RUNNERS";
			$runrparams[1] =  $_SESSION["transID"];
		 	$runrparams[2] = "";
		 	$runrparams[3] = "";
		 	$runrparams[4] = "";
		 	$runrparams[5] = "";
		 	$runrparams[6] = "";
			
			$addRunnerSQL =  "CALL SP_RUNNER('" . implode("', '", $runrparams) . "');";
		
			$addRunrResult = mysqli_query($mysqlLink, $addRunnerSQL);
				
			$addRunrrow = mysqli_fetch_object($addRunrResult);
			
			$totalFee += $addRunrrow->addedfee;
		?>
		<div class="formItem">
			<div class="formLabel" style="width:270px;"><?php echo "Added runners" ?></div>
			<div class="formLabelRight" style="width:90px;">Php <?php echo $raceData->rc_reg_fee ?></div>
			<div class="formLabelRight" style="width:90px;"><?php echo $addRunrrow->addedrunners ?></div>
			<div class="formLabelRight" style="width:90px;">Php <?php echo $addRunrrow->addedfee ?></div>
		</div>
		<?php 
		
			mysqli_free_result($addRunrResult);
			mysqli_next_result($mysqlLink); 
		}
		
		mysqli_close($mysqlLink);
		
		?>
		
		<div>
			<div style="width:580px;padding:2px 10px;">
				<hr class="hrDashedThin">
			</div>
		</div>
		<div>
			<div style="width:580px;padding:0px 10px;">
				<hr class="hrDashed">
			</div>
		</div>
		<div class="formItem" style="padding: 2px 20px;">
			<div class="formLabel" style="width:270px;">&nbsp;</div>
			<div class="formLabelRight" style="width:90px;">&nbsp;</div>
			<div class="formLabelRight" style="width:90px;font-weight: bold;">Total</div>
			<div class="formLabelRight" style="width:90px;font-weight: bold;">Php <?php echo $totalFee ?></div>
		</div>
		<div class="formItem">
			<div>&nbsp;</div>
		</div>
		<div class="formItem">
			<div class="formTitleLabel" style="width:140px;padding-top:2px;">PAYMENT OPTION: </div>
			<div><input type="radio" name="paymentMethod" value="PAYPAL" checked="checked" onclick="paymentOptionClick()"></div>
			<div class="formLabel" style="width:80px;">Paypal</div>
			<div><input type="radio" name="paymentMethod" value="CASH" onclick="paymentOptionClick()"></div>
			<div class="formLabel">Cash</div>
		</div>
		<div class="divSpacer"></div>
		<div id="cashPaymentDiv">
			<div class="formItem">
				<div class="formLabelRight" style="width:120px;">BIB:</div>
				<div class="formLabel"><input type="text" name="bibNumber" class="formInputNumbers" maxlength="10"/></div>
			</div>
			<div class="formItem">
				<div class="formLabelRight" style="width:120px;padding-top:2px;"><font color="#ff0000">*</font>Security Code: </div>
				<div class="formLabel" ><input type="password" name="securityCode"/></div>
				<div id="regOutletErrorMsg" class="formErrorMsg"/></div>
			</div>
		</div>
		<div class="formItem">
			<div>&nbsp;</div>
		</div>
	</div>
</div>

<?php
	} 
	else
		echo "<h2>".$row["err_code"]."</h2>";
?>
